//
//  NavigationViewController.m
//  TingLiFeng
//
//  Created by xinxuan on 16/1/3.
//  Copyright © 2016年 xinxuan. All rights reserved.
//

#import "NavigationViewController.h"
#import "MeViewController.h"
#import "MoreViewController.h"
#import "AllViewController.h"
#import "CommenModel.h"
//#import "DataHandel.h"
#import "StarLevelViewController.h"
@interface NavigationViewController ()<MXPullDownMenuDelegate>
@property(nonatomic,strong)NSMutableArray * modelsArray;
@end

@implementation NavigationViewController



//当第一次使用这个类的时候调用一次
//因为是控制所有的导航上的控件,所有要放在这里

+(void)initialize{
    
    //[self setUpBarButtonItem];
    [self setUpUINavigationBar];
}




+(void)setUpUINavigationBar{
    
    UINavigationBar * appearance = [UINavigationBar appearance];
    appearance.translucent = NO;
    appearance.barTintColor = navigatinBar_color_default;
    //设置导航栏背景(全局都会变)
    //[appearance setBackgroundImage:[UIImage imageNamed:@"navigationbar_background@2x.png"] forBarMetrics:(UIBarMetricsDefault)];
    //[appearance setBackgroundColor:[UIColor whiteColor]];
    //设置文字属性
    NSMutableDictionary * textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    
    //boldSystemFontOfSize 是粗体
    textAttrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20];
    //标题会有阴影,即由偏移,故只要设置偏移量为0 即可
    //UIOffsetZero是结构体,只有包装成NSValue对象 ,才能放进字典/数组中(只能放对象类型)
    //textAttrs[NSShadowAttributeName] = [NSValue valueWithUIOffset:UIOffsetZero];
    [appearance setTitleTextAttributes:textAttrs ];
    
}

/**
 *  能拦截所有push进来的子控制器
 */

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    NSLog(@"%lu",(unsigned long)self.viewControllers.count);
    
    if (self.viewControllers.count == 0) {
        // 如果现在push的不是栈底控制器(最先push进来的那个控制器)
        //viewController.hidesBottomBarWhenPushed = YES;
        
        viewController.view.backgroundColor = [UIColor whiteColor];
        // 设置导航栏按钮
        
        if (![viewController  isKindOfClass:[MeViewController class]]) {
            [self addMenuWithCotroller:viewController];
        }
        
        
    }else if (self.viewControllers.count == 1){
        
        viewController.view.backgroundColor = [UIColor whiteColor];
        // 设置导航栏按钮
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"返回" highImageName:nil target:self action:@selector(back)];
        
        if ([viewController  isKindOfClass:[MoreViewController class]] || [viewController  isKindOfClass:[AllViewController class]] ) {
            [self addMenuWithCotroller:viewController];
        }
        
    }else if (self.viewControllers.count > 1){
        
        viewController.view.backgroundColor = [UIColor whiteColor];
        // 设置导航栏按钮
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"返回" highImageName:nil target:self action:@selector(back)];
        
        
        
    }
    
    [super pushViewController:viewController animated:animated];
    
}


- (void)back
{
    //#warning 这里用的是self, 因为self就是当前正在使用的导航控制器
    [self popViewControllerAnimated:YES];
}


-(void)addMenuWithCotroller:(UIViewController*)controller{
    
    NSArray *testArray;
    testArray = @[ @[  @"按摩丰胸",@"热敷丰胸",@"理疗丰胸", @"全部课程" ], @[ @"丰胸"], @[@"1 ~ 2级", @"2 ~ 3级别", @"3 ~ 4级别"] ];
    
    MXPullDownMenu *menu = [[MXPullDownMenu alloc] initWithArray:testArray selectedColor:navigatinBar_color_default];
    menu.delegate = self;
    [controller.view addSubview:menu];
    
}



// 实现代理.
#pragma mark - MXPullDownMenuDelegate

- (void)PullDownMenu:(MXPullDownMenu *)pullDownMenu didSelectRowAtColumn:(NSInteger)column row:(NSInteger)row
{
    NSArray * nameArr = @[@"按摩课程",@"热敷课程",@"理疗课程"];
    //    NSString * nameString = [NSString new];
    if (column == 0) {
        
        if (row == 3) {
            AllViewController * all = [[AllViewController alloc]init];
            [self pushViewController:all animated:YES];
        }else{
            
            switch (self.playmode) {
                case anmo:{
                    MoreViewController * moreVc = [[MoreViewController alloc] init];
                    moreVc.name = nameArr[row];
                    moreVc.inNumber = self.viewControllers.count;
                    [self pushViewController:moreVc animated:YES];
                    break;
                }
                case refu:{
                    MoreViewController * moreVc = [[MoreViewController alloc] init];
                    moreVc.name = nameArr[row];
                    moreVc.inNumber = self.viewControllers.count;

                    [self pushViewController:moreVc animated:YES];
                    break;
                }
                case liliao:{
                    MoreViewController * moreVc = [[MoreViewController alloc] init];
                    moreVc.name = nameArr[row];
                    moreVc.inNumber = self.viewControllers.count;

                    [self pushViewController:moreVc animated:YES];
                    break;
                }
                    
                    
                default:
                    break;
            }
            
        }
        
    }else if (column == 2){

        switch (row) {
            case level1:{
                StarLevelViewController * starVC = [[StarLevelViewController alloc]init];
                starVC.starNumber1 = 1;
                starVC.starNumber2 = 2;
               [self pushViewController:starVC animated:YES];
                break;
            }
            case level2:{
                StarLevelViewController * starVC = [[StarLevelViewController alloc]init];
                starVC.starNumber1 = 2;
                starVC.starNumber2 = 3;
                [self pushViewController:starVC animated:YES];
                break;
            }
            case level3:{
                StarLevelViewController * starVC = [[StarLevelViewController alloc]init];
                starVC.starNumber1 = 3;
                starVC.starNumber2 = 4;
                [self pushViewController:starVC animated:YES];
                break;
            }
                
                
            default:
                break;
        }

    
       
    
    
    }
    
    
    
    
}



@end
